package yag.battle.pet.manager;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import yag.battle.pet.factory.EquipmentFactory;
import yag.battle.pet.factory.PetFactory;
import yag.battle.pet.model.Equipment;
import yag.battle.pet.model.Pet;
import yag.battle.pet.model.PetType;
import yag.battle.pet.service.EquipmentService;
import yag.battle.pet.service.PetService;

import java.util.List;

/**
 * Created by user on 31.08.2014.
 */
@Component
public class PetManager {
    @Autowired
    private PetService petService;
    @Autowired
    private EquipmentService equipmentService;
    @Autowired
    private PetFactory petFactory;
    @Autowired
    private EquipmentFactory equipmentFactory;


    public Pet createPet(PetType p) {
        Pet pet = petFactory.create(p);
        int id = petService.create(pet);
        pet.setId(id);
        Equipment eq = equipmentService.getByPetId(pet.getId());
        pet.setEquipment(eq);
        // pet.setEquipment();
        return pet;
    }

    public Pet getPetByUserId(int id) {
        Pet pet = petService.getByUser(id);
        pet.setEquipment(equipmentService.getByPetId(pet.getId()));
        return pet;
    }

    public Equipment createEquipment(String name) {
        Equipment eq = equipmentFactory.create(name);
        int id = equipmentService.create(eq);
        eq.setId(id);
        return eq;
    }

    public Equipment getEquipment(int id) {
        return equipmentService.getById(id);
    }

    public Equipment getPetEquioment(Pet pet) {
        return equipmentService.getByPetId(pet.getId());
    }

    public List<Equipment> getListEquioment() {
        return equipmentService.getList();

    }

    public void setPetEquipment(Pet pet, Equipment eq) {
        equipmentService.updateIdPetById(eq.getId(), pet.getId());
    }

    public void clearCurrentPetEquipment(Equipment eq) {
        equipmentService.deletePetIdById(eq.getId());
    }

    public void deleteEquipment(Equipment equipment) {
        equipmentService.deleteById(equipment.getId());
    }

    public Pet getPet(int id) {
        return petService.getById(id);
    }

    public void setPetUserId(int id, int userId) {
        petService.updateUserId(id, userId);
    }

    public void deleteUserIdById(int id) {

        petService.deleteUserIdById(id);
    }


}
